<?php

    namespace App\Models\V1_bak;

    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Support\Facades\DB;

    class Cart extends Model
    {
        /**
         * 获取购物车列表
         *
         * @param $userId
         *
         * @return array
         * author: walker
         * Date: 2019/10/23
         * Time: 15:46
         */
        public function getCartList($userId)
        {
            $where           = [];
            $where['UserId'] = $userId;
            $field           = "c.*,p.Name_en,p.CateId, p.PreFix, p.Number,
         p.AttrId, p.Attr, p.PageUrl, p.MOQ, p.Stock, p.SoldOut,
          p.IsSoldOut, p.SStartTime, p.SEndTime";
            return DB::table('shopping_cart as c')
                     ->leftJoin('products as p', 'c.ProId', '=', 'p.ProId')
                     ->where($where)
                     ->selectRaw($field)
                     ->get()
                     ->toArray();
        }

        public function countCart($userId)
        {
            $where           = [];
            $where['UserId'] = $userId;
            return DB::table('shopping_cart')
                     ->where($where)
                     ->sum('Qty');
        }
    }
